var ffmpeg = require('fluent-ffmpeg')

let startTime = new Date().getTime();
ffmpeg('C:\\Users\\ibo\\Desktop\\ff_test\\4k_test.m2ts')

    .output('C:\\Users\\ibo\\Desktop\\ff_test\\out\\flunt\\480\\index.mp4')
    .audioCodec('copy')
    .videoCodec('h264_nvenc')
    .size('?x480')
    .videoBitrate('256k')
    .renice(20)

    .output('C:\\Users\\ibo\\Desktop\\ff_test\\out\\flunt\\720\\index.mp4')
    .audioCodec('copy')
    .videoCodec('h264_nvenc')
    .size('?x720')
    .renice(19)

    .output('C:\\Users\\ibo\\Desktop\\ff_test\\out\\flunt\\1080\\index.mp4')
    .audioCodec('copy')
    .videoCodec('h264_nvenc')
    .size('?x1080')
    .renice(18)

    .output('C:\\Users\\ibo\\Desktop\\ff_test\\out\\flunt\\2k\\index.mp4')
    .audioCodec('copy')
    .videoCodec('h264_nvenc')
    .size('?x1440')
    .renice(17)

    .output('C:\\Users\\ibo\\Desktop\\ff_test\\out\\flunt\\4k\\index.mp4')
    .audioCodec('copy')
    .videoCodec('h264_nvenc')
    .size('?x2160')
    .renice(16)

    .outputOptions([
        '-strict -2'
    ])

    .on('start', function(commandLine) {
        console.log('Spawned Ffmpeg with command: ' + commandLine+"  time:"+startTime);
    })
    .on('progress', function(progress) {
        console.log('Processing: ' + progress.percent + '% done');
    })
    .on('end', function() {
        console.log('Processing finished !');
        console.log("startTime:"+startTime);
        console.log("totalTime:"+((new Date().getTime()) - startTime));
    })
    .on('error', function(err) {
        console.log('An error occurred: ' + err.message);
    })
    .run();